<?php
require_once("class/config.php");

$pw = "1234567890abcdefghijklmnopqrstuvwxyz";
function Password($length){
global $pw;
settype($length, "integer");
settype($rndstring, "string");
settype($a, "integer");
settype($b, "integer");

for ($a = 0; $a <= $length; $a++){
$b = rand(0, strlen($pw) - 1);
$rndstring .= $pw[$b];
}
return $rndstring;
}


if(!isset($_POST['send']) || empty($_POST['send'])){
 print('<center>
		<form action="" method="post">
        Username: <input type="text" name="name"><br>
        <input type="submit" name="send" value="Send">
        </form>
		</center>');
}elseif($_POST['send'] == 'Send'){
 $name = $_POST['name'];
 $name_q = mysql_query("SELECT user FROM login WHERE user='$name'");
 $row = mysql_fetch_object($name_q);
 
 if($row == 0){
	echo("<center>No user with this name!</center>");
	}else{
 
 $password = Password(6);
 $hash = md5($password);
 
 $email = mysql_query("SELECT email FROM login WHERE user='$name'");
 $e_mail = mysql_result($email, 0, 0);
 
 $headers = "MIME-Version: 1.0\r\n";
 $headers .= "Content-Type: text/html\r\n";


if (mail($e_mail, $mail_subject,
		'Hello '.$row->user.',<br>Here is your new password for '.$title.': <b>'.$password.'</b>',$headers)){
		mysql_query("UPDATE login SET password='$hash' WHERE user='$name'");
		echo('<center>Please check your mails!</center>');
		}else{
		echo('<center>We could not send you a mail!</center>');
}
}
}
?>